package com.huifaapp.mall.adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.huifaapp.mall.R;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.ArrayList;
import java.util.List;

/**
 * 品牌列表适配器
 */
public class ShareFriendGridViewAdapter extends BaseAdapter{

	private Context context;
	private LayoutInflater inflater;
	private ArrayList<String> mainImages;
	protected ImageLoader imageLoader = ImageLoader.getInstance();
	private boolean isChenck=false;
	private ArrayList<String> ar=new ArrayList<String>();
	public ShareFriendGridViewAdapter(Context context, ArrayList<String> mainImages){//, List<String> serviceareaList) {
		this.context = context;
		this.inflater = LayoutInflater.from(context);
		this.mainImages=mainImages;
	}
	@Override
	public int getCount() {
		return mainImages == null ? 0 : mainImages.size();
	}

	@Override
	public Object getItem(int position) {
		return mainImages.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	public ArrayList<String> getMainImages() {
		return mainImages;
	}

	public void setMainImages(ArrayList<String> mainImages) {
		this.mainImages = mainImages;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		final ViewHolder holder;
		
		if (null == convertView) {
			convertView = inflater.inflate(R.layout.sharefriend_gridview_item, null);
			holder = new ViewHolder();
			holder.iv_shareFriend_gridview_item_image= (ImageView) convertView.findViewById(R.id.iv_shareFriend_gridview_item_image);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		final String bean=mainImages.get(position);
		Log.e("数据","Gridviewbean=========="+bean);
		uploadimageview(holder.iv_shareFriend_gridview_item_image,bean,null,context);
		return convertView;
	}
	
	
	
	class ViewHolder {
		
		private ImageView iv_shareFriend_gridview_item_image;
	}

	public static void uploadimageview(final ImageView views, String url, String bili, Context c) {
		DisplayImageOptions HXOptions = new DisplayImageOptions.Builder()
				.cacheInMemory(true)
				.cacheOnDisk(true)
				.considerExifParams(true)
				.bitmapConfig(Bitmap.Config.RGB_565).build();
		ImageLoader.getInstance().displayImage(url, views, HXOptions);
	}
}
